/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2024-03-08
 * Time:21:01
 */
public class Solution {
    public int numDecodings(String s) {
        int n = s.length();
        if (n == 1) {
            if (s.charAt(0) == '0')
                return 0;
            else
                return 1;
        }

        int[] dp = new int[n];
        if (s.charAt(0) != '0')
            dp[0] = 1;
        if (dp[0] != 0) {
            if (s.charAt(1) != '0')
                dp[1] += 1;
            int t = (s.charAt(0) - '0') * 10 + s.charAt(1) - '0';
            if (t >= 10 && t <= 26)
                dp[1] += 1;
        }

        for (int i = 2; i < n; i++) {
            if (s.charAt(i) != '0')
                dp[i] += dp[i - 1];
            int tt = (s.charAt(i - 1) - '0') * 10 + s.charAt(i) - '0';
            if (tt >= 10 && tt <= 26)
                dp[i] += dp[i - 2];

        }
        return dp[n - 1];
    }
////////////////////////////////////////////
    //解密数字
public int crackNumber(int ciphertext) {
    if(ciphertext < 10) return 1;
    String str = String.valueOf(ciphertext);
    int[] dp = new int[str.length()];
    dp[0] = 1; dp[1] = 1;
    int t = (str.charAt(0) - '0')*10 + str.charAt(1) - '0';
    if(t >= 10 && t <= 25) dp[1]++;
    for(int i = 2;i < dp.length;i++) {
        dp[i] += dp[i-1];
        int tt = (str.charAt(i-1) - '0')*10 + str.charAt(i) - '0';
        if(tt >= 10 && tt <= 25) dp[i] += dp[i-2];
    }
    return dp[str.length()-1];
}

}
